package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.blnoruleyearvo.BlnoRuleYearCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnoruleyearvo.BlnoRuleYearPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnoruleyearvo.BlnoRuleYearRespVO;
import com.cmc.cloud.cmclink.doc.vo.blnoruleyearvo.BlnoRuleYearUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.BlnoRuleYearDO;
import com.cmc.cloud.cmclink.doc.service.BlnoRuleYearService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱号提单号规则 年份")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/RuleYear")
@Validated
public class BlnoRuleYearController {

    @Resource
    private BlnoRuleYearService blnoRuleYearService;

    @Operation(summary = "创建订舱号提单号规则 年份")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:yearCode:add')")
    public CommonResult<Void> createBlnoRuleYear(@Valid @RequestBody BlnoRuleYearCreateReqVO createReqVO) {
        blnoRuleYearService.createBlnoRuleYear(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新订舱号提单号规则 年份")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:yearCode:edit','doc:yearCode:enable'})")
    public CommonResult<Void> updateBlnoRuleYear(@Valid @RequestBody BlnoRuleYearUpdateReqVO updateReqVO) {
        blnoRuleYearService.updateBlnoRuleYear(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除订舱号提单号规则 年份")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:yearCode:delete')")
    public CommonResult<Void> deleteBlnoRuleYear(@PathVariable("id") Long id) {
        blnoRuleYearService.deleteBlnoRuleYear(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得订舱号提单号规则 年份")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<BlnoRuleYearRespVO> getBlnoRuleYear(@PathVariable("id") Long id) {
        BlnoRuleYearDO blnoRuleYear = blnoRuleYearService.getBlnoRuleYear(id);
        return CommonResult.success(BeanUtil.copyProperties(blnoRuleYear, BlnoRuleYearRespVO.class));
    }

    @Operation(summary = "获得订舱号提单号规则 年份列表")
    @GetMapping("/listAll")
    public CommonResult<List<BlnoRuleYearRespVO>> getBlnoRuleYearList() {
        List<BlnoRuleYearDO> list = blnoRuleYearService.getBlnoRuleYearList();
        return CommonResult.success(BeanUtil.copyToList(list,BlnoRuleYearRespVO.class));
    }

    @Operation(summary = "获得订舱号提单号规则 年份分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<BlnoRuleYearRespVO>> getBlnoRuleYearPage(@Valid @RequestBody BlnoRuleYearPageReqVO pageVO) {
        PageResult<BlnoRuleYearDO> pageResult = blnoRuleYearService.getBlnoRuleYearPage(pageVO);
        List<BlnoRuleYearRespVO> results = BeanUtil.copyToList(pageResult.getList(), BlnoRuleYearRespVO.class);
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
